package com.vitalc.biz.config;

import com.baomidou.mybatisplus.extension.api.R;
import com.vitalc.service.exception.BizException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author chenzihao
 * @Date 2020/12/14
 * @Description 全局异常处理类
 */
@RestControllerAdvice
public class ExceptionHandle {
    
    private static final Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);
    
    @ExceptionHandler({BizException.class})
    public R handBizException(BizException e) {
        e.printStackTrace();
        logger.error("Business processing error , e : {}", e.getMessage());
        return R.failed(e.getMessage());
    }
    
    @ExceptionHandler(Exception.class)
    public R handException(Exception e) {
        e.printStackTrace();
        logger.error("unKnow error , e : {}", e.getMessage());
        return R.failed(e.getMessage());
    }
    
}
